import { ref } from 'vue';
import { useTable, LIST_TYPE } from '@crud/index';
import { getList } from '@/api/crm-kgj/invest-product';
import { optionsProductStatus } from '@/config/index';
import { toolOptions2Map } from '@/utils';

export const useData = () => {
  const statusOptions = ref(optionsProductStatus);
  const statusMap = toolOptions2Map(statusOptions.value);

  return {
    statusOptions,
    statusMap
  };
};
export const useTableList = () => {
  const columns = [
    { label: '商品信息', prop: 'product', width: 320, render: 'product' },
    { label: '店铺', prop: 'shop', align: 'center', minWidth: 130, render: 'shop' },
    { label: '价格', prop: 'price', align: 'center', minWidth: 120, type: 'priceCent' },
    { label: '佣金率', prop: 'cos_ratio', align: 'right', minWidth: 120, render: (s: any) => (s.row.cos_ratio == undefined ? '-' : s.row.cos_ratio + '%') },
    {
      label: '商品状态',
      prop: 'status',
      align: 'center',
      render: (s: any) => (s.row.is_sold_out ? '已下架' : '已上架'),
      minWidth: 120
    },
    { label: '关联达人/销量', prop: 'relate_gmv', align: 'center', minWidth: 180, render: 'relate_gmv' },
    { label: '操作', align: 'center', width: 120, render: 'actions', fixed: 'right' }
  ];

  return useTable({
    type: LIST_TYPE.KGJ,
    params: {
      keyword: undefined,
      shop_name: undefined,
      lv1: undefined,
      product_status: undefined
    },
    getParams: (params) => {
      return params;
    },
    columns,
    getList
  });
};
